package com.atguigu.flow.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.commonutils.R;
import com.atguigu.flow.entity.vo.CurrentUser;
import com.atguigu.flow.entity.vo.TokenInfoBO;
import com.atguigu.flow.service.IwInstanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URLDecoder;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-03-01
 */
@Api(description="审批流管理")
@RestController
@RequestMapping("/workflow")
public class IwInstanceController {
    @Autowired
    private
    IwInstanceService iwInstanceService;
    private static final Logger logapp = LoggerFactory.getLogger("applog");

    @ApiOperation(value = "工作流审批")
    @PostMapping("workflow_approve")
    public
    R workflow_approve(@RequestBody String msg,@CurrentUser TokenInfoBO tokenInfoBO)throws Exception {
        System.out.println(tokenInfoBO);
        msg= URLDecoder.decode(msg);
        msg=msg.replace("msg=","");

        JSONObject msgJson = JSONObject.parseObject(msg);
        logapp.info(msgJson.toJSONString());
        String recordid =msgJson.getString("recordid");
        String modulename =msgJson.getString("modulename");
        Boolean isgree=msgJson.getBoolean("isgree");
        String username=msgJson.getString("username");
        String content=msgJson.getString("content");
        String spectime=msgJson.getString("spectime");

        String str=iwInstanceService.flow_agree(recordid,modulename,isgree,username,content,spectime);


        return R.ok().data("modulename",modulename).data("approve_result",str);
//        return R.ok().data("msg",msgJson.toJSONString());
    }







}

